package com.example.demo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@SpringBootApplication
public class DemoApplication {

    private static final AtomicInteger counter = new AtomicInteger(0);


    public static void main0(String[] args) {
        final ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        SpringApplication application = new SpringApplication();
        if (counter.get() == 0) {
            context.publishEvent(new ApplicationFailedEvent(application, new String[0],
                    context, new RuntimeException("something take error")));
        }
        counter.incrementAndGet();
    }

    public static void main(String[] args) throws IOException {
        SpringApplication.run(DemoApplication.class, args);
//        final CAResponse token = SZCA_API.getToken();
//        log.info("result: {}", token.getData());
    }
}
